/**
  * CR_SubInterface Object
  *
  * Building block object used to create Sub User Interfaces within a UI. Includes
  * show and hide methods that hide its UI. Also makes room for the addition of
  * methods to control input.
  *
  * @param {String} uiName The name of the Sub UI
  * @param {String} resource The resource string used to create this Sub UI
  * @param {Group} This Sub UI's parent Group object
  */
function CR_SubInterface(uiName, resource, Parent_UI)
{
    /*** Private Variables ***/

    /**
     *The name of this include
     */
    var scriptName = "CR_SubInterface.jsx";

    /**
     *The name of this SUI
     */
    var uiName = uiName;

    /**
     *The resource string that defines this Sub UI
     */
    var res = resource;

    /**
     *A reference to this Sub UI's outtermost ScriptUI object
     */
    var myUI = null;

    try
    {
        myUI = Parent_UI.add(res);
    }catch(e){
        throw(CR_Error(errors.COULDNT_PARSE_SUI + " " + uiName, e, $.stack, scriptName));
    }
    /*** Public Methods ***/

    return {
        /**
         *Shows this Sub UI
         */
        UI : myUI,
        show : function() {
            if(myUI !== null)
            {
                debug(uiName + " -> show()");
                try
                {
                    myUI.show();
                    return true;
                }catch(e){
                    raiseError(CR_Error(errors.COULDNT_SHOW_SUI + " " + uiName, e, $.stack, scriptName));
                    return false;
                }
             }else{
                return false;
            }
        },
        hide : function() {
            if(myUI !== null)
            {
                debug(uiName + " -> hide()");
                try
                {
                    //dumpProps(myUI);
                    myUI.hide();
                    return true;
                }catch(e){
                    raiseError(CR_Error(errors.COULDNT_HIDE_SUI + " " + uiName, e, $.stack, scriptName));
                    return false;
                }
            }else{
                return false;
            }
        },
        toString: function() {
          return uiName;
        }
    }
}